package com.hk.rabbitmq.six;

import com.hk.rabbitmq.utils.RabbitMqUtils;
import com.rabbitmq.client.BuiltinExchangeType;
import com.rabbitmq.client.Channel;
import com.rabbitmq.client.DeliverCallback;
import org.apache.commons.io.FileUtils;

import java.io.File;

/**
 * @author: dpb
 * @date: 2022/3/22
 */
public class ReceiveDirect02 {
    private static final String EXCHANGE_NAME = "direct logs";
    public static void main(String[] args) throws Exception{

        Channel channel = RabbitMqUtils.getChannel();
        channel.exchangeDeclare(EXCHANGE_NAME, BuiltinExchangeType.DIRECT);

        String queueName = "console";
        channel.queueDeclare(queueName,false,false,false,null);
        //绑定
        channel.queueBind(queueName,EXCHANGE_NAME,"info");
        channel.queueBind(queueName,EXCHANGE_NAME,"warning");
        System.out.println("等待接收消息......");

        DeliverCallback deliverCallback = (consumerTag, message) -> {
            String msg = new String(message.getBody(),"UTF-8");
            System.out.println("接收绑定主键为：" + message.getEnvelope().getRoutingKey() + "，消息为：" + msg);
        };
        channel.basicConsume(queueName, true, deliverCallback, cancelCallback -> {
        });
    }
}
